<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/11/12
  Time: 21:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css">
<link rel="stylesheet"
      href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/hplus/css/plugins/sweetalert/sweetalert.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/static/hplus/js/plugins/sweetalert/sweetalert.min.js"></script>
<body>
<div class="panel panel-default">
    <div class="panel-body">
        <input class="form-control" placeholder="请输入姓名" id="name"><br>
        性别 男<input type="radio" value="0" checked name="ra">
        女 <input type="radio" value="1" name="ra"><br>
        部门 <select class="select btn-default"></select>
        <input class="form-control" placeholder="请输入签到日期" id="data"><br>
        <button class="btn btn-block" onclick="add()">添加</button>
    </div>
</div>

</body>
<script>
    $.ajax({
        url: '${pageContext.request.contextPath}/user/select',
        success: function (data) {
            for (var i in data) {
                var id = data[i].deptid;
                var name = data[i].deptName;
                var str = "<option class='option' value=" + id + ">" + name + "</option>"
                $('.select').append(str)
            }
        }
    })

    function add() {
        var staffName = $('#name').val();
        var sex = $("input[name='ra']:checked").val();
        var depeld = $('.select').val();
        var data = $('#data').val();

        if (staffName == null || staffName == '') {
            swal({
                title: "姓名不能为空",
                type: "error"
            })
        } else if (data == null || data == '') {
            swal({
                title: "日期不能为空",
                type: "error"
            })
        }


        $.ajax({
            url: "${pageContext.request.contextPath}/user/add",
            data: {
                "staffName": staffName,
                "sex": sex,
                "depeld": depeld,
                "data": data
            },
            success: function (data) {
                if (data > 0) {
                    swal({
                            title: "添加成功",
                            type: "success",
                            confirmButtonText: "OK"
                        },
                        function (data) {
                            if (data) {
                                window.location.href = "userlist.jsp"
                            }
                        });

                }
            }
        })
    }


</script>
</html>
